package com.esbi.projectwebsocket.changeFileTpye;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

public class FileTransfer {
    public static void main(String[] args) {
        String sourceFolderPath = "C:\\Users\\zxwes\\Desktop\\source";//直接新建一个源文件夹source和目标文件夹target
        String targetFolderPath = "C:\\Users\\zxwes\\Desktop\\target";

        File sourceFolder = new File(sourceFolderPath);
        File targetFolder = new File(targetFolderPath);

        if (!sourceFolder.exists() ||!targetFolder.exists()) {
            System.out.println("源文件夹或目标文件夹不存在。");
            return;
        }

        for (File subFolder : sourceFolder.listFiles(File::isDirectory)) {
            for (File file : subFolder.listFiles()) {
                try {
                    Files.move(file.toPath(), new File(targetFolder, file.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        System.out.println("文件转移完成。");
        System.out.print("\33[44;1m"+"已经从"+sourceFolderPath+"转移到文件夹"+targetFolderPath+"\n\33[0m");//紫色背景
    }
}